package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {
    /**
     *  新增菜品
     * @param dish
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")// 设置主键回填
    @AutoFill(OperationType.INSERT)
    @Insert("insert into dish (name, category_id, price, image, description, status, create_time, update_time, create_user, update_user) " +
            "values " +
            "(#{name}, #{categoryId}, #{price}, #{image}, #{description}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})" )
    void insert(Dish dish);

    /**
     * 分页查询菜品信息
     *
     * @param dishPageQueryDTO
     * @return
     */
    List<DishVO> page(DishPageQueryDTO dishPageQueryDTO);

    /**
     *  根据id查询菜品
     * @param id
     * @return
     */
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    /**
     *  修改菜品
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    /**
     * 批量删除菜品
     *
     * @param ids
     * @return
     */
     void deleteByIds(List<Long> ids);

    /**
     *  根据id批量查询菜品的启售数量
     * @param ids
     * @param status
     * @return
     */
    Long countStatusByIds(List<Long> ids,Integer status);

    /**
     *  根据分类id查询菜品的id
     * @param categoryId
     * @return
     */
    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> getByCategoryId(Long categoryId);

    /**
     * 根据套餐查询查询菜品
     * @param setmealId
     * @return
     */
    @Select("select d.description,d.image,d.name,sd.copies from dish d left join setmeal_dish sd on d.id = sd.dish_id where setmeal_id = #{setmealId}")
    List<DishItemVO> getBysetmealId(Long setmealId);
}
